//
//  PreLoginContrillor.swift
//  maopu
//
//  Created by huazi on 2017/4/30.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class PreLoginContrillor: BaseViewController {
    fileprivate var imageLogo: UIImageView!
    fileprivate var btnOldLogin: UIButton!
    fileprivate var btnNewRegister: UIButton!
    fileprivate var btnSeeSee: UIButton!  //随便逛逛
    fileprivate var thirdLoginView: ThirdLoginView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initView()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    internal func initView(){
        let imageLogoLenth: CGFloat = 80.0
        var top: CGFloat = 60.0
        let left: CGFloat = 15.0
        let btnHeight: CGFloat = 40.0
        
        
        self.imageLogo = UIImageView.init(frame: CGRect.init(x: AppWidth/2-40.0, y: top, width: imageLogoLenth, height: imageLogoLenth))
        self.imageLogo.image = UIImage.init(named: "test_header")
        self.imageLogo.setCircel()
        self.view.addSubview(self.imageLogo)
        top += imageLogoLenth + 30.0
        
        self.btnOldLogin = UIButton.init(frame: CGRect.init(x: left, y: top, width: AppWidth-2*left, height: btnHeight))
        self.btnOldLogin.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#ffce54")), for: .normal)
        self.btnOldLogin.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#dcb34c")), for: .highlighted)
        self.btnOldLogin.setTitle("老猫登录", for: .normal)
        self.btnOldLogin.setCornerRadius(radius: 20.0)
        self.btnOldLogin.titleLabel?.font = UIFont.LightDefaultFont(13.0)
        self.btnOldLogin.setTitleColor(UIColor.black, for: .normal)
        self.btnOldLogin.addTarget(self, action: #selector(btnOldLoginClick), for: .touchUpInside)
        self.view.addSubview(self.btnOldLogin)
        top += btnHeight + 20.0
        
        self.btnNewRegister = UIButton.init(frame: CGRect.init(x: left, y: top, width: AppWidth-2*left, height: btnHeight))
        self.btnNewRegister.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#f7f7f7")), for: .normal)
        self.btnNewRegister.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#f1f1f1")), for: .highlighted)
        self.btnNewRegister.setTitle("小猫注册", for: .normal)
        self.btnNewRegister.setCornerRadius(radius: 20.0)
        self.btnNewRegister.titleLabel?.font = UIFont.LightDefaultFont(13.0)
        self.btnNewRegister.setTitleColor(UIColor.black, for: .normal)
        self.btnNewRegister.layer.borderColor = UIColor.colorWithHexString(hex: "#f1f1f1").cgColor
        self.btnNewRegister.layer.borderWidth = 1.0
        self.btnNewRegister.addTarget(self, action: #selector(btnNewRegisterClick), for: .touchUpInside)
        self.view.addSubview(self.btnNewRegister)
        top += btnHeight + 20.0
        
        self.btnSeeSee = UIButton.init(frame: CGRect.init(x: left, y: top, width: AppWidth-2*left, height: btnHeight))
        self.btnSeeSee.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#f7f7f7")), for: .normal)
        self.btnSeeSee.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#f1f1f1")), for: .highlighted)
        self.btnSeeSee.setTitle("随便逛逛", for: .normal)
        self.btnSeeSee.titleLabel?.font = UIFont.LightDefaultFont(13.0)
        self.btnSeeSee.setTitleColor(UIColor.black, for: .normal)
        self.btnSeeSee.setCornerRadius(radius: 20.0)
        self.btnSeeSee.addTarget(self, action: #selector(btnSeeSeeClick), for: .touchUpInside)
        self.view.addSubview(self.btnSeeSee)
        top += btnHeight + 20.0
        
        
        self.thirdLoginView = ThirdLoginView.init(frame: CGRect.init(x: 0, y: AppHeight-150, width: AppWidth, height: 150))
        self.thirdLoginView.delegate = self
        self.view.addSubview(self.thirdLoginView)
        
    }
    @objc fileprivate func btnOldLoginClick(){
//        let vc = LoginController()
//        self.navigationController?.pushViewController(vc, animated: true)
        ShareSDK.authorize(SSDKPlatformType.typeWechat, settings: [:]) { (state : SSDKResponseState, user : SSDKUser?, error : Error?) in
            
        }
    }
    @objc fileprivate func btnNewRegisterClick(){
        let vc = RegisterController()
        self.navigationController?.pushViewController(vc, animated: true)
    }
    @objc fileprivate func btnSeeSeeClick(){
//        self.navigationController?.popViewController(animated: true)
        let vc = SeeSeeAuthPhoneController()
        self.navigationController?.pushViewController(vc, animated: true)
        
        
    }
    
    
}

extension PreLoginContrillor: ThirdLoginViewDelegate {
    func thirdLoginViewitemClick(index: Int) {
        if index == 100 {
            ShareSDK.authorize(SSDKPlatformType.typeQQ, settings: [:]) { (state : SSDKResponseState, user : SSDKUser?, error : Error?) in
                
            }
        }
        if index == 101 {
            ShareSDK.authorize(SSDKPlatformType.typeWechat, settings: [:]) { (state : SSDKResponseState, user : SSDKUser?, error : Error?) in
                
            }
        }
        if index == 102 {
            ShareSDK.authorize(SSDKPlatformType.typeSinaWeibo, settings: [:]) { (state : SSDKResponseState, user : SSDKUser?, error : Error?) in
                
            }
        }
    }
}

